﻿/*
Jumble 
Time Limit:1000MS  Memory Limit:32768K

  
Description:
Your objective for this question is to develop a program which will take in a "vocabulary list" of real words, 
and a "jumbled list" of words whose letters are scrambled,
and for each word return either the list of words that the jumbled word could be,
or the fact that the jumbled word couldn't be any word it knows.

Input:
Your inputs include two blocks. The first block is of real words newline delimited that will be the program's "knowledge base".
The second block is of the jumbled word list newline delimited. 
A jumbled word is a word whose letters have be reordered.
For example, the real word ball may produce the jumbled word labl.
Other considerations: For simplicity, 
you may assume that your vocabulary is no more than 1000 words and that the number of jumbled words to consider
is no more than 50 words.
You SHOULD NOT assume your words in either list are "one word", i.e., your words may contain spaces. 
Output:
Your output should follow the format below.
Jumbled words that match the vocabulary should return those words in a space delimited list and ASCII ordered, 
but with the space after the last word replaced with a newline.
Jumbled words that do not match should return "no match" as a result. 
Sample Input:
ball
bear
tab
bat
trickle down
lick
click
clock
rim
mir
rmi

abll
irm
abt
kcja

Sample Output:
abll: ball
irm: mir rim rmi
abt: bat tab
kcja: no match
*/
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
bool match(const string& s, const string& t)
{
	if(s.length()!=t.length())return false;
	for (string::size_type i=0, size=s.length(); i<size; ++i)
		if(string::npos==t.find_first_of(s[i]))
			return false;
	return true;			
}
int main()
{
	vector<string> bases;
	for (string input; getline(cin, input) && ""!=input;)
		bases.push_back(input);
	for (string jumble; getline(cin, jumble);)
	{
		set<string> matches;
		for (vector<string>::iterator it=bases.begin(); it!=bases.end(); ++it)
			if(match(jumble, *it))
				matches.insert(*it);
		cout<<jumble<<":";
		if(matches.empty())
		{
			cout<<" no match"<<endl;
		}
		else
		{
			for (set<string>::iterator i=matches.begin(); i!=matches.end(); ++i)
				cout<<" "<<*i;
			cout<<endl;
		}

	}
	return 0;
}